package com.geek.ch04;

import java.util.Objects;
import java.util.function.DoubleBinaryOperator;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/9/4
 */
public class User {
    private String name;
    private String password;

    @Override//重写equals方法，用于比较两个User对象的内容是否相等
    public boolean equals(Object obj) {

        // 1. 检查是否为同一个对象引用，是则直接返回true
        if(this == obj) return true;

        // 2. 检查对象是否为null或类型是否不同，满足任一条件则返回false
        //    确保比较的对象是非空的且是User类或其子类的实例
        if(obj == null||this.getClass()!=obj.getClass()) return false;

        User user = (User) obj;

        // 4. 比较两个对象的name和password字段是否都相等
        return name.equals(user.name) && password.equals(user.password);
    }
    @Override//重写hashCode方法，返回基于对象字段值的哈希码
    public int hashCode(){
        return Objects.hash(name,password);
    }
    public User() {
    }

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * 设置
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString() {
        return "User{name = " + name + ", password = " + password + "}";
    }
}
